<?php

/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitepage
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: AdminDefaultlayoutController.php 2011-05-05 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */
class Sitepage_AdminDefaultlayoutController extends Core_Controller_Action_Admin {
	
	//ACTION FOR SETTING THE DEFAULT LAYOUT
	public function indexAction() {
		
		//GET NAVIGATION
		$this->view->navigation = Engine_Api::_ ()->getApi ( 'menus', 'core' )->getNavigation ( 'sitepage_admin_main', array (), 'sitepage_admin_main_layoutdefault' );
		
		//FORM   
		$this->view->form = $form = new Sitepage_Form_Admin_Layoutdefault ();
		
		//GET PAGE PROFILE PAGE INFO
		$selectPage = Engine_Api::_ ()->sitepage ()->getWidgetizedPage ();
		if (! empty ( $selectPage )) {
			$this->view->page_id = $selectPage->page_id;
		}
		
		//FORM VALIDATION
		if ($this->getRequest ()->isPost () && $form->isValid ( $this->getRequest ()->getPost () )) {
			//GET FORM VALUES
			$values = $form->getValues ();
			
			//GET ADMIN CONTENT TABLE
			$contentTable = Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' );
			
			//GET ADMIN CONTENT TABLE NAME
			$contentTableName = $contentTable->info ( 'name' );
			
			//GET SITEPAGE CONTENT TABLE
			$sitepagecontentTable = Engine_Api::_ ()->getDbtable ( 'content', 'sitepage' );
			
			//CORE CONTENT TABLE
			$corecontentTable = Engine_Api::_ ()->getDbtable ( 'content', 'core' );
			
			//GET SITEPAGE CONTENT PAGES TABLE
			$sitepagepageTable = Engine_Api::_ ()->getDbtable ( 'contentpages', 'sitepage' );
			
			//GET HIDE PROFILE WODGET TABLE   
			$hideprofilewidgetsTable = Engine_Api::_ ()->getDbtable ( 'hideprofilewidgets', 'sitepage' );
			
			//DELETING THE OLD ENTRIES
			$hideprofilewidgets = $hideprofilewidgetsTable->select ()->query ()->fetchAll ();
			if (! empty ( $hideprofilewidgets )) {
				foreach ( $hideprofilewidgets as $data ) {
					$hideprofilewidgetsTable->delete ( array ('hideprofilewidgets_id =?' => $data ['hideprofilewidgets_id'] ) );
				}
			}
			$layout_option = $_POST ['sitepage_sitepage_layout_setting'];
			
			$selectsitepagePage = $sitepagepageTable->select ()->from ( $sitepagepageTable->info ( 'name' ), array ('contentpage_id' ) )->where ( 'name =?', 'sitepage_index_view' );
			$contentpages_id = $selectsitepagePage->query ()->fetchAll ();
			foreach ( $contentpages_id as $key => $value ) {
				$sitepagecontentTable->delete ( array ('contentpage_id =?' => $value ['contentpage_id'] ) );
				if (empty ( $layout_option )) {
					Engine_Api::_ ()->getDbtable ( 'content', 'sitepage' )->setWithoutTabLayout ( $value ['contentpage_id'] );
				} else {
					Engine_Api::_ ()->getDbtable ( 'content', 'sitepage' )->setTabbedLayout ( $value ['contentpage_id'] );
				}
			}
			
			if (! empty ( $layout_option )) {
				include_once APPLICATION_PATH . '/application/modules/Sitepage/controllers/AdminviewpagewidgetController.php';
				if (! empty ( $selectPage )) {
					$page_id = $selectPage->page_id;
					$contentTable->delete ( array ('page_id =?' => $page_id ) );
					Engine_Api::_ ()->getApi ( 'layoutcore', 'sitepage' )->setTabbedLayoutContent ( $page_id );
				}
				
				if (! empty ( $page_id )) {
					//INSERT MAIN CONTAINER
					$mainContainer = $contentTable->createRow ();
					$mainContainer->page_id = $page_id;
					$mainContainer->type = 'container';
					$mainContainer->name = 'main';
					$mainContainer->order = 2;
					$mainContainer->save ();
					$container_id = $mainContainer->admincontent_id;
					
					//INSERT MAIN-MIDDLE CONTAINER
					$mainMiddleContainer = $contentTable->createRow ();
					$mainMiddleContainer->page_id = $page_id;
					$mainMiddleContainer->type = 'container';
					$mainMiddleContainer->name = 'middle';
					$mainMiddleContainer->parent_content_id = $container_id;
					$mainMiddleContainer->order = 6;
					$mainMiddleContainer->save ();
					$middle_id = $mainMiddleContainer->admincontent_id;
					
					//INSERT MAIN-LEFT CONTAINER
					$mainLeftContainer = $contentTable->createRow ();
					$mainLeftContainer->page_id = $page_id;
					$mainLeftContainer->type = 'container';
					$mainLeftContainer->name = 'left';
					$mainLeftContainer->parent_content_id = $container_id;
					$mainLeftContainer->order = 4;
					$mainLeftContainer->save ();
					$left_id = $mainLeftContainer->admincontent_id;
					$showmaxtab = Engine_Api::_ ()->getApi ( 'settings', 'core' )->getSetting ( 'sitepage.showmore', 8 );
					
					//INSERT MAIN-MIDDLE TAB CONTAINER
					$middleTabContainer = $contentTable->createRow ();
					$middleTabContainer->page_id = $page_id;
					$middleTabContainer->type = 'widget';
					$middleTabContainer->name = 'core.container-tabs';
					$middleTabContainer->parent_content_id = $middle_id;
					$middleTabContainer->order = 7;
					$middleTabContainer->params = "{\"max\":\"$showmaxtab\"}";
					$middleTabContainer->save ();
					$middle_tab = $middleTabContainer->admincontent_id;
					
					//INSERTING THUMB PHOTO WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.thumbphoto-sitepage', $middle_id, 1 );
					
					//INSERTING TITLE WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.title-sitepage', $middle_id, 2 );
					
					//INSERTING LIKE WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.page-like-button', $middle_id, 3 );
					
					//INSERTING FACEBOOK LIKE WIDGET
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'facebookse' )) {
						Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'Facebookse.facebookse-sitepageprofilelike', $middle_id, 4 );
					}
					
					//INSERTING PHOTO STRIP WIDGET
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
						Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.photorecent-sitepage', $middle_id, 5 );
					}
					
					//INSERTING MAIN PHOTO WIDGET 
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.mainphoto-sitepage', $left_id, 10 );
					
					//INSERTING OPTIONS WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.options-sitepage', $left_id, 11 );
					
					//INSERTING INFORMATION WIDGET 
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.information-sitepage', $left_id, 14, 'Information', 'true' );
					
					//INSERTING WRITE SOMETHING ABOUT WIDGET 
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.page-like', $left_id, 15 );
					
					//INSERTING RATING WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagereview' )) {
						Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepagereview.ratings-sitepagereviews', $left_id, 16, 'Ratings' );
					}
					
					//INSERTING BADGE WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagebadge' )) {
						Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepagebadge.badge-sitepagebadge', $left_id, 17, 'Badge' );
					}
					
					//INSERTING YOU MAY ALSO LIKE WIDGET 
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.suggestedpage-sitepage', $left_id, 18, 'You May Also Like' );
					
					//INSERTING SOCIAL SHARE WIDGET 
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.socialshare-sitepage', $left_id, 19, 'Social Share' );
					
					//INSERTING FOUR SQUARE WIDGET 
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.foursquare-sitepage', $left_id, 20 );
					
					//INSERTING INSIGHTS WIDGET 
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.insights-sitepage', $left_id, 21, 'Insights' );
					
					//INSERTING FEATURED OWNER WIDGET 
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.featuredowner-sitepage', $left_id, 22, 'Owners' );
					
					//INSERTING ALBUM WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
						Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.albums-sitepage', $left_id, 23, 'Albums' );
					}
					
					//INSERTING PAGE PROFILE PLAYER WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagemusic' )) {
						Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepagemusic.profile-player', $left_id, 24 );
					}
					
					//INSERTING LINKED PAGES WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.favourite-page', $left_id, 25, 'Linked Pages' );
					
					//INSERTING ACTIVITY FEED WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'socialengineaddon.feed', $middle_tab, 1, 'Updates', 'true' );
					
					//INSERTING INFORAMTION WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.info-sitepage', $middle_tab, 2, 'Info', 'true' );
					
					//INSERTING OVERVIEW WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.overview-sitepage', $middle_tab, 3, 'Overview', 'true' );
					
					//INSERTING LOCATION WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.location-sitepage', $middle_tab, 4, 'Map', 'true' );
					
					//INSERTING LINKS WIDGET
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'core.profile-links', $middle_tab, 125, 'Links', 'true' );
					
					//INSERTING ALBUM WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepage.photos-sitepage', $page_id, 'Photos', 'true', '110' );
					}
					
					//INSERTING VIDEO WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagevideo' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepagevideo.profile-sitepagevideos', $page_id, 'Videos', 'true', '111' );
					}
					
					//INSERTING NOTE WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagenote' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepagenote.profile-sitepagenotes', $page_id, 'Notes', 'true', '112' );
					}
					
					//INSERTING REVIEW WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagereview' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepagereview.profile-sitepagereviews', $page_id, 'Reviews', 'true', '113' );
					}
					
					//INSERTING FORM WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepageform' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepageform.sitepage-viewform', $page_id, 'Form', 'false', '114' );
					}
					
					//INSERTING DOCUMENT WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagedocument' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepagedocument.profile-sitepagedocuments', $page_id, 'Documents', 'true', '115' );
					}
					
					//INSERTING OFFER WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepageoffer' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepageoffer.profile-sitepageoffers', $page_id, 'Offers', 'true', '116' );
					}
					
					//INSERTING EVENT WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepageevent' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepageevent.profile-sitepageevents', $page_id, 'Events', 'true', '117' );
					}
					
					//INSERTING POLL WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagepoll' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepagepoll.profile-sitepagepolls', $page_id, 'Polls', 'true', '118' );
					}
					
					//INSERTING DISCUSSION WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagediscussion' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepage.discussion-sitepage', $page_id, 'Discussions', 'true', '119' );
					}
					
					//INSERTING MUSIC WIDGET 
					if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagemusic' )) {
						Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminDefaultInfo ( 'sitepagemusic.profile-sitepagemusic', $page_id, 'Music', 'true', '120' );
					}
				}
			} else {
				//IF EMPTY THEN MAKE PAGE PROFILE PAGE
				if (empty ( $selectPage )) {
					$pageCreate = $pageTable->createRow ();
					$pageCreate->name = 'sitepage_index_view';
					$pageCreate->displayname = 'Page Profile';
					$pageCreate->title = 'Page Profile';
					$pageCreate->description = 'This is the page view  page.';
					$pageCreate->custom = 1;
					$current_page_id = $pageCreate->save ();
				} else {
					$current_page_id = $selectPage->page_id;
				}
				
				if (! empty ( $current_page_id )) {
					$corecontentTable->delete ( array ('page_id =?' => $current_page_id ) );
					Engine_Api::_ ()->getApi ( 'layoutcore', 'sitepage' )->setWithoutTabContent ( $current_page_id );
				}
				
				if (! empty ( $selectPage )) {
					$page_id = $selectPage->page_id;
					$contentTable->delete ( array ('page_id =?' => $page_id ) );
				}
				//INSERT MAIN CONTAINER
				$mainContainer = $contentTable->createRow ();
				$mainContainer->page_id = $page_id;
				$mainContainer->type = 'container';
				$mainContainer->name = 'main';
				$mainContainer->order = 2;
				$mainContainer->save ();
				$container_id = $mainContainer->admincontent_id;
				
				//INSERT MAIN-MIDDLE CONTAINER.
				$mainMiddleContainer = $contentTable->createRow ();
				$mainMiddleContainer->page_id = $page_id;
				$mainMiddleContainer->type = 'container';
				$mainMiddleContainer->name = 'middle';
				$mainMiddleContainer->parent_content_id = $container_id;
				$mainMiddleContainer->order = 6;
				$mainMiddleContainer->save ();
				$middle_id = $mainMiddleContainer->admincontent_id;
				
				//INSERT MAIN-LEFT CONTAINER.
				$mainLeftContainer = $contentTable->createRow ();
				$mainLeftContainer->page_id = $page_id;
				$mainLeftContainer->type = 'container';
				$mainLeftContainer->name = 'left';
				$mainLeftContainer->parent_content_id = $container_id;
				$mainLeftContainer->order = 4;
				$mainLeftContainer->save ();
				$left_id = $mainLeftContainer->admincontent_id;
				
				//INSERTING TITLE WIDGET
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.title-sitepage', $middle_id, 2 );
				
				//INSERTING LIKE WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.page-like-button', $middle_id, 3 );
				
				//INSERTING FACEBOOK LIKE WIDGET
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'facebookse' )) {
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'Facebookse.facebookse-sitepageprofilelike', $middle_id, 4 );
				}
				
				//INSERTING PHOTO STRIP WIDGET   
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.photorecent-sitepage', $middle_id, 5 );
				}
				
				//INSERTING ACTIVITY FEED WIDGET
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'socialengineaddon.feed', $middle_id, 6, 'Updates', 'true' );
				
				//INSERTING INFORAMTION WIDGET
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.info-sitepage', $middle_id, 7, 'Info', 'true' );
				
				//INSERTING OVERVIEW WIDGET
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.overview-sitepage', $middle_id, 8, 'Overview', 'true' );
				
				//INSERTING LOCATION WIDGET
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.location-sitepage', $middle_id, 9, 'Map', 'true' );
				
				//INSERTING LINKS WIDGET  
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'core.profile-links', $middle_id, 125, 'Links', 'true' );
				
				//INSERTING MAIN PHOTO WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.mainphoto-sitepage', $left_id, 10 );
				
				//INSERTING WIDGET LINK WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.widgetlinks-sitepage', $left_id, 11 );
				
				//INSERTING OPTIONS WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.options-sitepage', $left_id, 12 );
				
				//INSERTING WRITE SOMETHING ABOUT WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.write-page', $left_id, 13 );
				
				//INSERTING INFORMATION WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.information-sitepage', $left_id, 14, 'Information', 'true' );
				
				//INSERTING LIKE WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.page-like', $left_id, 15 );
				
				//INSERTING RATING WIDGET 	
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagereview' )) {
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepagereview.ratings-sitepagereviews', $left_id, 16, 'Ratings' );
				}
				
				//INSERTING BADGE WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagebadge' )) {
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepagebadge.badge-sitepagebadge', $left_id, 17, 'Badge' );
				}
				
				//INSERTING SOCIAL SHARE WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.socialshare-sitepage', $left_id, 19, 'Social Share' );
				
				//INSERTING FOUR SQUARE WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.foursquare-sitepage', $left_id, 20 );
				
				//INSERTING INSIGHTS WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.insights-sitepage', $left_id, 22, 'Insights' );
				
				//INSERTING FEATURED OWNER WIDGET 
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.featuredowner-sitepage', $left_id, 23, 'Owners' );
				
				//INSERTING ALBUM WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagealbum' )) {
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.albums-sitepage', $left_id, 24, 'Albums' );
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepage.photos-sitepage', $page_id, 'Photos', 'true', '110' );
				}
				
				//INSERTING PAGE PROFILE PLAYER WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagemusic' )) {
					Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepagemusic.profile-player', $left_id, 25 );
				}
				
				//INSERTING LINKED PAGES WIDGET   
				Engine_Api::_ ()->sitepage ()->setDefaultDataWidget ( $contentTable, $contentTableName, $page_id, 'widget', 'sitepage.favourite-page', $left_id, 26, 'Linked Pages' );
				
				//INSERTING VIDEO WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagevideo' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepagevideo.profile-sitepagevideos', $page_id, 'Videos', 'true', '111' );
				}
				
				//INSERTING NOTE WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagenote' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepagenote.profile-sitepagenotes', $page_id, 'Notes', 'true', '112' );
				}
				
				//INSERTING REVIEW WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagereview' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepagereview.profile-sitepagereviews', $page_id, 'Reviews', 'true', '113' );
				}
				
				//INSERTING FORM WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepageform' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepageform.sitepage-viewform', $page_id, 'Form', 'false', '114' );
				}
				
				//INSERTING DOCUMENT WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagedocument' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepagedocument.profile-sitepagedocuments', $page_id, 'Documents', 'true', '115' );
				}
				
				//INSERTING OFFER WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepageoffer' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepageoffer.profile-sitepageoffers', $page_id, 'Offers', 'true', '116' );
				}
				
				//INSERTING EVENT WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepageevent' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepageevent.profile-sitepageevents', $page_id, 'Events', 'true', '117' );
				}
				
				//INSERTING POLL WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagepoll' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepagepoll.profile-sitepagepolls', $page_id, 'Polls', 'true', '118' );
				}
				
				//INSERTING DISCUSSION WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagediscussion' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepage.discussion-sitepage', $page_id, 'Discussions', 'true', '119' );
				}
				
				//INSERTING MUSIC WIDGET 
				if (Engine_Api::_ ()->getDbtable ( 'modules', 'core' )->isModuleEnabled ( 'sitepagemusic' )) {
					Engine_Api::_ ()->getDbtable ( 'admincontent', 'sitepage' )->setAdminContentDefaultInfoWithoutTab ( 'sitepagemusic.profile-sitepagemusic', $page_id, 'Music', 'true', '120' );
				}
			}
			$value = $_POST ['sitepage_sitepage_layout_setting'];
			Engine_Api::_ ()->getApi ( "settings", "core" )->setSetting ( 'sitepage.layout.setting', $value );
		}
	}
	
	//ACTION FOR SAVING THE LAYOUT
	public function savelayoutAction() {
		
		$this->_helper->layout->setLayout ( 'admin-simple' );
	}
}

?>